#include "ComeToScene.h"

ComeToScene::ComeToScene(QGraphicsScene *scene)
{
    root = QFileInfo(__FILE__).absolutePath();
    pix = QPixmap(root+"/res/colorful_spiral.png");
    rotation = 0; //#旋转角度
    rotatespeed = 10; //旋转速度

    opacity = 1;
    scene->addItem(this);
}

QRectF ComeToScene::boundingRect() const
{
    return QRectF(-pix.width() * 0.5, -pix.height() * 0.5, pix.width(), pix.height());
}

void ComeToScene::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setOpacity(opacity);
    painter->drawPixmap(-pix.width()*0.5,-pix.height()*0.5,pix);
}

void ComeToScene::updateAnimation()
{
    opacity -= 0.02;    //提高透明度

    rotatespeed += 5;   //加速旋转
    rotation = (rotation+rotatespeed)%360;
    this->setRotation(rotation);
    this->update();
}
